package com.fingard.dsp.bank.reqrespobj.single;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RequestBase;
import com.fingard.dsp.bank.reqrespobj.single.detail.ReqPayRecDetail;
import com.fingard.xml.XmlReadMode;
import com.fingard.xml.XmlTextReader;

//单笔合批请求对象
public class ReqSingleBat extends RequestBase {
/*<TotalNum>总笔数</TotalNum>
      <TotalAmt>总金额</TotalAmt>
      <ReqBatchNO>批号</ReqBatchNO>
   <DetailRecord>
    <PayName></PayName>
    <PayAct></PayAct>
        <PayBankName></PayBankName>
    <PayBnk></PayBnk>
    <PayArea></PayArea>
    <PayAreaName></PayAreaName>
    <RecName></RecName>
    <RecAct></RecAct>
        <RecBankName></RecBankName>
    <RecBnk></RecBnk>
    <RecArea></RecArea>
    <RecAreaName></RecAreaName>
        <RecStandardArea>区域名称</RecStandardArea>
    <SameCity></SameCity>
    <SameBnk></SameBnk>
    <PayDate></PayDate>
    <PayTime></PayTime>
    <PayAmount></PayAmount>
    <PayCur></PayCur>
    <RecCur></RecCur>
    <Usage></Usage>
    <PaySpd></PaySpd>
    <SubmitID></SubmitID>
    <ReqSeqID></ReqSeqID>
    <PostScript></PostScript>
    <Memo></Memo>
    <InnerPay></InnerPay>
        <RootPay></RootPay>
        <RootRec></RootRec>
        <IsPrivate></IsPrivate>
        <CNAPSCode></CNAPSCode>
        <CNAPSName></CNAPSName>
    <ReqReserved1></ReqReserved1>
    <ReqReserved2></ReqReserved2>
   </DetailRecord>*/

    public String totalNum = "";
    public String totalAmt = "";
    public String reqBatchNO = "";//批次号，跟ATS数据库字段保持一致
    /**是否重用批次号*/
    public String reuseSeq = "";

    private XmlTextReader xmlReader;
    public ReqSingleBat(XmlTextReader p_xmlReader, ReqRespHeader p_header) throws Exception{
        reqHeader = p_header;
        xmlReader = p_xmlReader;
        totalNum = xmlReader.getSimpleText("TotalNum");
        totalAmt = xmlReader.getSimpleText("TotalAmt");
        reqBatchNO = xmlReader.getSimpleText("ReqBatchNO");
        reuseSeq = xmlReader.getSimpleText("ReuseSeq");

    }
    public ReqPayRecDetail readedDetail;//复用singlepay.detail.ReqPayRecDetail
    public boolean readRecord() throws Exception{
        readedDetail = null;
        if(xmlReader.read(PATH_Detail)){
            readedDetail = new ReqPayRecDetail(xmlReader.readedXElement, reqHeader.transType,reqHeader.bankCode);
            return true;
        }
        else{
            return false;
        }
    }

    //是否有跨行交易
    public boolean hasOtherBank() throws Exception{
        boolean retValue = false;
        xmlReader.resetReadMode(XmlReadMode.XElementReader);
        while(xmlReader.read(PATH_Detail+"/SameBnk")){
            if(xmlReader.readedXElement.innerText.equals("0")){
                retValue = true;
                break;
            }
        }
        xmlReader.resetReadMode(XmlReadMode.XElementReader);
        return retValue;
    }

    //加急标志是否一致
    public boolean isSamePaySpd() throws Exception{
        boolean retValue = true;
        String tmpPaySpd = "";
        xmlReader.resetReadMode(XmlReadMode.XElementReader);
        while(xmlReader.read(PATH_Detail+"/PaySpd")){
            if(tmpPaySpd.length() == 0){
                tmpPaySpd = xmlReader.readedXElement.innerText;
            }
            else if(!xmlReader.readedXElement.innerText.equals(tmpPaySpd)){
                retValue = false;
                break;
            }

        }
        xmlReader.resetReadMode(XmlReadMode.XElementReader);
        return retValue;
    }

    public  String isPrivate = "";
    //公私标志是否一致
    public boolean hasPayPub() throws Exception{
        boolean retValue = true;
        xmlReader.resetReadMode(XmlReadMode.XElementReader);
        while(xmlReader.read(PATH_Detail+"/IsPrivate")){
            if(isPrivate.length() == 0){
                isPrivate = xmlReader.readedXElement.innerText;
            }
            else if(!xmlReader.readedXElement.innerText.equals(isPrivate)){
                retValue = false;
                break;
            }

        }
        xmlReader.resetReadMode(XmlReadMode.XElementReader);
        return retValue;
    }


    public int getTotalNum(){
        return Integer.parseInt(totalNum);
    }

    public BigDecimal getTotalAmt(){
        return new BigDecimal(totalAmt);
    }
}
